//
//  CJDivsionMianViewController.m
//  CoJellyCartoon
//
//  Created by dllo on 16/3/30.
//  Copyright © 2016年 CJG. All rights reserved.
//

#import "CJDivsionMianViewController.h"
#import "CJDivsionMainModel.h"
#import "CJDivColllectionVIewCell.h"
@interface CJDivsionMianViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic, strong) NSMutableArray *datasource;
@property (nonatomic, copy) NSString *path;
@property (nonatomic, retain) id result;
@property (nonatomic, strong) UICollectionView *divCollectionView;

@end

@implementation CJDivsionMianViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     self.view.backgroundColor = [UIColor whiteColor];
   
    self.path = [[NSBundle mainBundle] pathForResource:@"DivCell" ofType:@"plist"];
    
    self.result = [NSMutableArray arrayWithContentsOfFile:self.path];
    
    self.datasource = [NSMutableArray arrayWithCapacity:0];
    
    for (NSDictionary *dic in self.result) {
        CJDivsionMainModel *divmodel = [[CJDivsionMainModel alloc] init];
        [divmodel setValuesForKeysWithDictionary:dic];
        [self.datasource addObject:divmodel];
    }
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    flowlayout.itemSize = CGSizeMake(self.view.frame.size.width/8, self.view.frame.size.height/4);
    flowlayout.minimumInteritemSpacing = 0;
    flowlayout.minimumLineSpacing = 0;
    flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    self.divCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width-20, self.view.frame.size.height- 64) collectionViewLayout:flowlayout];
     self.divCollectionView.backgroundColor = [UIColor whiteColor];
    self.divCollectionView.dataSource = self;
    self.divCollectionView.delegate = self;
    [self.divCollectionView registerClass:[CJDivColllectionVIewCell class] forCellWithReuseIdentifier:@"CJDivColllectionVIewCell"];
    [self.view addSubview:self.divCollectionView];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.datasource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CJDivColllectionVIewCell *item = [collectionView dequeueReusableCellWithReuseIdentifier:@"CJDivColllectionVIewCell" forIndexPath:indexPath];
    CJDivsionMainModel *divmodel = self.datasource[indexPath.item];
    item.divMainModel = divmodel;
    return item;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
